package com.kinoshita.admin.generator;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.po.LikeTable;
import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.keywords.MySqlKeyWordsHandler;

import java.util.Collections;

/**
 * MyBatis-Plus 的代码生成器，
 * <p>
 * 通过 AutoGenerator
 *
 * @author Reagan
 */
public class MyBatisPlusGenerator {

    public static void main(String[] args) {
        AutoGenerator autoGenerator = new AutoGenerator(getDataSourceConfig());
        autoGenerator.global(getGlobalConfig());
        autoGenerator.packageInfo(gerPackageConfig());
        autoGenerator.strategy(getStrategyConfig());
        autoGenerator.template(getTemplateConfig());
        autoGenerator.execute();
    }

    public static DataSourceConfig getDataSourceConfig() {
        return new DataSourceConfig.Builder("jdbc:mysql://127.0.0.1:3306/manager","root","1234")
                .dbQuery(new MySqlQuery())
                .schema("manager")
                .typeConvert(new MySqlTypeConvert())
                .keyWordsHandler(new MySqlKeyWordsHandler()).build();
    }

    public static GlobalConfig getGlobalConfig() {
        return new GlobalConfig.Builder()
                .outputDir("L:/新建文件夹/framerwork/admin/admin-core/src/main/java")
                .author("reagan")
                .dateType(DateType.TIME_PACK)
                .commentDate("yyyy-MM-dd")
                .build();

    }

    public static PackageConfig gerPackageConfig() {
        return new PackageConfig.Builder()
                .parent("com.kinoshita.admin")
                .entity("entity")
                .service("service")
                .serviceImpl("service.impl")
                .mapper("mapper")
                .xml("mapper.xml")
                .controller("controller")
                .other("other")
                .pathInfo(Collections.singletonMap(OutputFile.xml, "L:/新建文件夹/framerwork/admin/admin-root/src/main/resources/mapper"))
                .build();
    }

    public static TemplateConfig getTemplateConfig() {
        return new TemplateConfig.Builder()
                .disable(TemplateType.ENTITY)
                .entity("/templates/entity.java")
                .service("/templates/service.java")
                .serviceImpl("/templates/serviceImpl.java")
                .mapper("/templates/mapper.java")
                .xml("/templates/mapper.xml")
                .controller("/templates/controller.java")
                .build();
    }

    public static StrategyConfig getStrategyConfig() {
        return new StrategyConfig.Builder()
                .enableCapitalMode()
                .enableSkipView()
                .disableSqlFilter()
                .addInclude("sys_permission")
                .addTablePrefix("sys", "")
                .build();
    }
}
